/*
 * Copyright (C) 2017-2021
 * All rights reserved, Designed By 深圳中科鑫智科技有限公司
 * Copyright authorization contact 18814114118
 */
package com.shop.cereshop.app.service.product.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.cereshop.app.dao.product.CereShopProductDAO;
import com.shop.cereshop.app.dao.product.CereSkuNameDAO;
import com.shop.cereshop.app.service.product.CereSkuNameService;
import com.shop.cereshop.commons.domain.product.CereShopProduct;
import com.shop.cereshop.commons.domain.product.CereSkuName;
import com.shop.cereshop.commons.domain.product.bo.CereSkuNameBo;
import com.shop.cereshop.commons.domain.product.vo.CereSkuNameVo;
import com.shop.cereshop.commons.domain.shop.CereShopGroup;
import com.shop.cereshop.commons.domain.shop.bo.CereShopGroupBo;
import com.shop.cereshop.commons.domain.shop.vo.CereShopGroupVo;
import org.assertj.core.util.Lists;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class CereSkuNameServiceImpl extends ServiceImpl<CereSkuNameDAO,  CereSkuName> implements CereSkuNameService {

    /**
     * 条件构造器
     */
    public LambdaQueryWrapper<CereSkuName> buildLambdaQueryWrapper(CereSkuNameBo param){
        LambdaQueryWrapper<CereSkuName> q1 = new LambdaQueryWrapper<>();
        q1.eq(ObjectUtil.isNotEmpty(param.getSkuId()),CereSkuName::getSkuId,param.getSkuId());
        q1.in(CollectionUtil.isNotEmpty(param.getSkuIds()),CereSkuName::getSkuId,param.getSkuIds());
        return q1;
    }

    /**
     * 条件查询
     */
    public List<CereSkuNameVo> queryList(CereSkuNameBo param){
        List<CereSkuName> list = list(buildLambdaQueryWrapper(param));

        if (CollectionUtil.isNotEmpty(list)){
            return generate(list);
        }
        return null;
    }
    /**
     * 根据规格id查询sku参数
     */
    public List<CereSkuNameVo> queryListBySkuId(Long skuId){
        CereSkuNameBo bo = new CereSkuNameBo();
        bo.setSkuId(skuId);
        return queryList(bo);
    }

    @Override
    public List<CereSkuNameVo> queryListBySkuId(List<Long> skuIds) {
        CereSkuNameBo bo = new CereSkuNameBo();
        bo.setSkuIds(skuIds);
        return queryList(bo);
    }

    /**
     * 转换函数
     */
    public List<CereSkuNameVo> generate(List<CereSkuName> list){
        List<CereSkuNameVo> cereSkuNameVos = Lists.newArrayList();
        for (CereSkuName cereSkuName : list) {
            CereSkuNameVo cereSkuNameVo = new CereSkuNameVo();
            BeanUtils.copyProperties(cereSkuName,cereSkuNameVo);
            cereSkuNameVos.add(cereSkuNameVo);
        }
        return cereSkuNameVos;
    }

    /**
     * 转换函数
     */
    public CereSkuNameVo generate(CereSkuName cereSkuName) {
        CereSkuNameVo cereSkuNameVo = new CereSkuNameVo();
        BeanUtils.copyProperties(cereSkuName,cereSkuNameVo);
        return cereSkuNameVo;
    }
}
